package com.example.yan_music.base.presenter;

import com.example.yan_music.base.view.IView;
import com.example.yan_music.model.DataModel;
import com.example.yan_music.model.net.NetworkActionImp;
import com.example.yan_music.model.net.RetrofitFactory;

/**
 * 所有的 Presenter 的基类
 * @param <T> 要绑定的 View (界面)
 */
public class BasePresenter<T extends IView> implements IPresenter<T>{

    // 拿到 View 层对象
    protected T mView;

    // 拿到 M 层
    protected DataModel mModel;

    public BasePresenter() {
       if(mModel == null){
           mModel = new DataModel(new NetworkActionImp(RetrofitFactory.createRequest()));
       }
    }

    /**
     *  关联View
     * @param view
     */
    @Override
    public void attachView(T view) {
        mView = view;
    }

    @Override
    public void detachView() {
        mView = null;
    }
}
